//============================================================================
// Name        : cyinterview.cpp
// Author      : cy
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

void swap(char *x, char *y) {
	char temp;
	temp = *x;
	*x = *y;
	*y = temp;
}
/* Function to print permutations of string
 This function takes three parameters:
 1. String
 2. Starting index of the string
 3. Ending index of the string. */
void permute(char *a, int i, int n) {
	int j;
	if (i == n) {
		printf("%s\n", a);
//		std::cout << a;
	}
	else {
		for (j = i; j <= n; j++) {
			swap((a + i), (a + j));
			permute(a, i + 1, n);
			swap((a + i), (a + j)); //backtrack
		}
	}
}
int main() {
	char a[] = "ABC";
	permute(a, 0, 2);
	getchar();
	return 0;
}
